package com.xmgps.bdt.interfaces.bokun;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author zeno.w
 * @date 2022/4/8
 */
@Slf4j
@Component
public class DeviceCommunicationStartupListener implements DisposableBean {

    @Autowired
    private DeviceCommunicationServer communicationServer;


    @EventListener(ApplicationReadyEvent.class)
    public void onStart(ApplicationReadyEvent event){
        try {
            communicationServer.start();
        } catch (InterruptedException e) {
            log.error("博琨设备通讯服务启动失败！！！");
            throw new RuntimeException("博琨设备通讯服务启动失败！！！");
        }
    }

    @Override
    public void destroy() throws Exception {
    }
}
